package org.example5;

public class IntList {
	public int first;
	public IntList rest;

	public IntList(int f ,IntList r) {
		first  = f;
		rest = r ;
	}

	/**
	 * return the size of the list using ...recursion!
	 * @return
	 */
	public int size() {
		if (rest==null) {
			return 1;
		}else {
				return 1 + this.rest.size();
		}
	}

	public int interativeSize() {
		IntList p  = this;
		int totalSize=0 ;
		while(p!=null) {
			totalSize+=1;
			p = p.rest;
		}
		return totalSize;
	}

	public int get(int i) {
		if (i==0) {
			return first;
		}else {
			return rest.get(i-1);
		}
	}


	public static void main(String[] args) {
		IntList L = new IntList(15,null);
		L = new IntList(10,L);
		L = new IntList(5,L);

		System.out.println(L.size());
		System.out.println(L.interativeSize());
		System.out.println(L.get(2));



	}
} 